<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Bootstrap - 简洁、直观、强悍、移动设备优先的前端开发框架，让web开发更迅速、简单。">
    <meta name="author" content="Bootstrap中文网">

    <title>

        美人黛&middot;接口文档

    </title>

    <link href="../dist/css/bootstrap.min.css" rel="stylesheet">


    <!-- Documentation extras -->
    <link href="../dist/css/docs.css" rel="stylesheet">
    <link href="../dist/css/github.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../dist/hl-styles/tomorrow-night-eighties.css"/>
    <style>
        body {
            font-family: "ff-tisa-web-pro-1", "ff-tisa-web-pro-2", "Lucida Grande", "Helvetica Neue", Helvetica, Arial, "Hiragino Sans GB", "Hiragino Sans GB W3", "WenQuanYi Micro Hei", sans-serif;
        }

        h1, .h1, h2, .h2, h3, .h3, h4, .h4, .lead {
            font-family: "ff-tisa-web-pro-1", "ff-tisa-web-pro-2", "Lucida Grande", "Helvetica Neue", Helvetica, Arial, "Hiragino Sans GB", "Hiragino Sans GB W3", "Microsoft YaHei UI", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
        }

        /*pre code {*/
        /*background: transparent;*/
        /*}*/

        @media (min-width: 768px) {
            .bs-docs-home .bs-social,
            .bs-docs-home .bs-masthead-links {
                margin-left: 0;
            }
        }

        .bs-docs-section p {
            line-height: 2;
        }

        .bs-docs-section p.lead {
            line-height: 1.4;
        }

        div#alertModal.modal.fade.bs-example-modal-sm.in {
            overflow: hidden;
        }

    </style>

    <!--[if lt IE 9]>
    <script src="../dist/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="../dist/js/html5shiv.min.js"></script>
    <script src="../dist/js/respond.min.js"></script>
    <![endif]-->

    <!-- Favicons -->
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="../dist/images/apple-touch-icon-144-precomposed.png">
    <link rel="shortcut icon" href="../dist/images/favicon.png">


</head>
<body>
<a class="sr-only" href="#content">Skip to main content</a>

<!-- Docs master nav -->
<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
    <div class="container">
        <div class="navbar-header">
            <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="#" class="navbar-brand">接口文档</a>
        </div>
        <nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
            <ul class="nav navbar-nav">
                <%
                apps.forEach(function(app){
                %>
                <li class="pt-<%=app.pathName%>">
                    <a href="/view-<%=app.pathName%>"><%=app.name%></a>
                </li>
                <%
                });
                %>
                <!--<li class="pt-appInterface-0410">-->
                <!--<a href="/view-appInterface-0410">Version4.1</a>-->
                <!--</li>-->
                <!--<li class="pt-appInterface-0420">-->
                <!--<a href="/view-appInterface-0420">Version4.2</a>-->
                <!--</li>-->
                <!--<li class="pt-armyInterface">-->
                <!--<a href="/view-armyInterface">军工项目</a>-->
                <!--</li>-->
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li>
                    <a id="toView" href="#">浏览文档</a>
                </li>
            </ul>
        </nav>
    </div>
</header>

<!-- Docs page layout -->
<div class="bs-header" id="content">
    <div class="container">
        <h1>概述(接口管理)</h1>

        <p>所有api均为http请求，get请求参数为QueryString格式，post请求体为json格式，Content-Type为application/json;
            charset=UTF-8</p>

    </div>
</div>

<!-- Callout for the old docs link -->

<div id="confirmModal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">是否确认</h4>
            </div>
            <div class="modal-body alert-confirm-content">

            </div>
            <div class="modal-footer">
                <button id="confirmNeed" type="button" class="btn btn-default alert-confirm-cancel">取消</button>
                <button type="button" class="btn btn-primary alert-confirm-ok">确定</button>
            </div>

        </div>
    </div>
</div>

<div id="moduleEditModal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">模块编辑</h4>
            </div>
            <div class="modal-body">
                <form id="moduleForm">
                    <div class="form-group">
                        <label for="mCode">模块代码</label>
                        <input type="text" class="form-control" id="mCode" placeholder="模块代码">
                        <input type="hidden" id="mId">
                    </div>
                    <div class="form-group">
                        <label for="mName">模块名称</label>
                        <input type="text" class="form-control" id="mName" placeholder="模块名称">
                    </div>
                    <div class="form-group">
                        <label for="mOrder">模块排序</label>
                        <input type="text" class="form-control" id="mOrder" placeholder="模块排序">
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button id="btnSaveModule" type="button" class="btn btn-primary">提交</button>
            </div>

        </div>
    </div>
</div>

<div id="ifEditModal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">接口编辑</h4>
            </div>
            <div class="modal-body">
                <div>
                    <!-- Nav tabs -->
                    <ul class="nav nav-tabs" role="tablist">
                        <li role="presentation" class="active"><a href="#base" aria-controls="base" role="tab"
                                                                  data-toggle="tab" id="ifEditFirstTab">基础信息</a></li>
                        <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">参数设置</a>
                        </li>
                        <li role="presentation"><a href="#messages" aria-controls="messages" role="tab"
                                                   data-toggle="tab">返回示例</a></li>
                        <li role="presentation"><a id="iAttr" href="#settings" aria-controls="settings" role="tab"
                                                   data-toggle="tab">属性描述</a></li>
                    </ul>

                    <form id="ifForm">
                        <!-- Tab panes -->
                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane active" id="base">
                                <div class="form-group">
                                    <label for="iModule">所属模块</label>
                                    <select class="form-control" id="iModule">
                                        <% list.forEach(function(mObj){ %>
                                        <option value="<%= mObj.interfaceId %>"><%= mObj.name %></option>
                                        <% }) %>
                                    </select>
                                    <input type="hidden" id="iId">
                                </div>
                                <div class="form-group">
                                    <label for="iName">接口作者</label>
                                    <input type="text" class="form-control" id="iAuthor" placeholder="接口编写人">
                                </div>
                                <div class="form-group">
                                    <label for="iName">接口名称</label>
                                    <input type="text" class="form-control" id="iName" placeholder="接口名称">
                                </div>
                                <div class="form-group">
                                    <label for="iUrl">接口URL</label>
                                    <input type="text" class="form-control" id="iUrl" placeholder="接口URL">
                                </div>
                                <div class="form-group">
                                    <label for="iOrder">接口描述</label>
                                    <textarea class="form-control" rows="4" id="iDesc" placeholder="接口描述"></textarea>
                                </div>
                                <div class="form-group">
                                    <label for="iOrder">接口排序</label>
                                    <input type="text" class="form-control" id="iOrder" placeholder="接口排序">
                                </div>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="profile">
                                <br>
                                <div class="btn-group">
                                    <button id="btnParamFormType" type="button" class="btn btn-default active">表单式参数
                                    </button>
                                    <button id="btnParamJSONType" type="button" class="btn btn-default">JSON请求体</button>
                                </div>
                                <table class="table table-striped" id="formTypeTable">
                                    <thead>
                                    <tr>
                                        <th scope="col" class="col-xs-3">参数名称</th>
                                        <th scope="col" class="col-xs-7">参数描述</th>
                                        <th scope="col" class="col-xs-2">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody id="iTableParam">
                                    <tr class="param-first-row">
                                        <td><input class="form-control input-sm param-name" type="text"
                                                   placeholder="参数名称"></td>
                                        <td><input class="form-control input-sm param-desc" type="text"
                                                   placeholder="参数描述"></td>
                                        <td align="center">
                                            <button type="button" class="btn btn-success btn-sm param-btn-add">
                                                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                                            </button>
                                        </td>
                                    </tr>

                                    </tbody>
                                </table>

                                <table class="table table-striped hide" id="jsonTypeTable">
                                    <thead>
                                    <th scope="col" class="col-xs-3">参数名称</th>
                                    <th scope="col" class="col-xs-9">参数描述</th>
                                    </thead>

                                    <tbody>
                                    <tr id="paramDemoRow">
                                        <td colspan="2">JSON示例<strong id="paramJSONFault">(请填写正确的JSON格式)</strong></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <textarea class="form-control" rows="7" id="paramJSONDemo"></textarea>
                                        </td>
                                    </tr>
                                    </tbody>
                                    <tbody id="paramAttrRow">

                                    </tbody>
                                </table>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="messages">
                                <div class="form-group">
                                    <label for="iResultDemo">请使用JSON格式</label>
                                    <textarea class="form-control" rows="7" id="iResultDemo"></textarea>
                                </div>
                                <div class="json-check-alert alert alert-danger" role="alert" style="display:none;">
                                    <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
                                    <span class="sr-only">警告:</span>
                                    JSON格式错误,属性列表将无法编辑
                                </div>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="settings">
                                <table class="table table-striped">
                                    <thead>
                                    <tr>
                                        <th scope="col" class="col-xs-3">属性名称</th>
                                        <th scope="col" class="col-xs-7">属性描述</th>
                                    </tr>
                                    </thead>
                                    <tbody id="iTableProp">

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button id="btnSaveIf" type="button" class="btn btn-primary">提交</button>
            </div>

        </div>
    </div>
</div>

<div id="jspEditModal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">JSP配置编辑</h4>
            </div>
            <div class="modal-body">
                <div>
                    <!-- Nav tabs -->
                    <ul class="nav nav-tabs" role="tablist">
                        <li role="presentation" class="active"><a href="#jspBase" aria-controls="jspBase" role="tab"
                                                                  data-toggle="tab" id="jspEditFirstTab">基础信息</a></li>
                        <li role="presentation"><a href="#jspData" aria-controls="jspData" role="tab"
                                                   data-toggle="tab">数据示例</a></li>
                        <li role="presentation"><a id="jAttr" href="#jspSettings" aria-controls="jspSettings" role="tab"
                                                   data-toggle="tab">属性描述</a></li>
                    </ul>

                    <form id="jspForm">
                        <!-- Tab panes -->
                        <div class="tab-content">
                            <div role="tabpanel" class="tab-pane active" id="jspBase">
                                <div class="form-group">
                                    <label for="jModule">所属模块</label>
                                    <select class="form-control" id="jModule">
                                        <% list.forEach(function(mObj){ %>
                                        <option value="<%= mObj.interfaceId %>"><%= mObj.name %></option>
                                        <% }) %>
                                    </select>
                                    <input type="hidden" id="jId">
                                </div>
                                <div class="form-group">
                                    <label for="jAuthor">页面文档作者</label>
                                    <input type="text" class="form-control" id="jAuthor" placeholder="页面文档作者">
                                </div>
                                <div class="form-group">
                                    <label for="jName">页面名称</label>
                                    <input type="text" class="form-control" id="jName" placeholder="页面名称">
                                </div>
                                <div class="form-group">
                                    <label for="jUrl">页面访问URL</label>
                                    <input type="text" class="form-control" id="jUrl" placeholder="页面访问URL">
                                </div>
                                <div class="form-group">
                                    <label for="jPage">页面资源路径</label>
                                    <input class="form-control" type="text" id="jPage" placeholder="页面资源路径"/>
                                </div>
                                <div class="form-group">
                                    <label for="jOrder">文档排序</label>
                                    <input type="text" class="form-control" id="jOrder" placeholder="文档排序">
                                </div>
                            </div>

                            <div role="tabpanel" class="tab-pane" id="jspData">
                                <div class="form-group">
                                    <label for="jResultDemo">请使用JSON格式</label>
                                    <textarea class="form-control" rows="7" id="jResultDemo"></textarea>
                                </div>
                                <div class="json-check-alert alert alert-danger" role="alert" style="display:none;">
                                    <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
                                    <span class="sr-only">警告:</span>
                                    JSON格式错误,属性列表将无法编辑
                                </div>
                            </div>
                            <div role="tabpanel" class="tab-pane" id="jspSettings">
                                <table class="table table-striped">
                                    <thead>
                                    <tr>
                                        <th scope="col" class="col-xs-3">属性名称</th>
                                        <th scope="col" class="col-xs-7">属性描述</th>
                                    </tr>
                                    </thead>
                                    <tbody id="jTableProp">

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button id="btnSaveJspPage" type="button" class="btn btn-primary">提交</button>
            </div>

        </div>
    </div>
</div>


<div class="container bs-docs-container">
    <div class="row">
        <div class="col-md-3">
            <div class="bs-sidebar hidden-print" role="complementary">
                <ul class="nav bs-sidenav">
                    <li>
                        <a href="#modulesManage">模块管理</a>
                    </li>
                    <li>
                        <a href="#ifManage">接口管理</a>
                        <ul class="nav">
                            <%
                            var mIndex = 0;
                            list.forEach(function(mObj){ %>
                            <li><a href="#<%=mObj.interfaceId%>"><%=++mIndex%>&nbsp; <%=mObj.name%></a></li>
                            <%})%>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
        <div class="col-md-9" role="main">

            <div class="bs-docs-section">
                <div class="page-header">
                    <h1 id="modulesManage">模块管理</h1>
                </div>
                <p class="lead">模块列表</p>

                <p><a class="btn btn-primary" href="#" role="button" id="newModule">新增模块</a></p>

                <table class="table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th scope="col" class="col-xs-3">模块代码</th>
                        <th scope="col" class="col-xs-4">模块名称</th>
                        <th scope="col" class="col-xs-2">模块排序</th>
                        <th scope="col" class="col-xs-3">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <% list.forEach(function(mObj){ %>
                    <tr>
                        <td valign="center" data-objattr="mCode"><%= mObj.code %></td>
                        <td valign="center" data-objattr="mName"><%= mObj.name %></td>
                        <td valign="center" data-objattr="mOrder"><%= mObj.order %></td>
                        <td valign="center">
                            <div class="btn-group">
                                <button type="button" class="btn btn-info dropdown-toggle btn-xs" data-toggle="dropdown"
                                        aria-haspopup="true" aria-expanded="false">
                                    模块操作 <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu">
                                    <li><a href="#" class="mana-module-modify" data-mid="<%= mObj.interfaceId %>"><span
                                                    class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 修改</a>
                                    </li>
                                    <li role="separator" class="divider"></li>
                                    <li><a href="#" class="mana-module-delete" data-mid="<%= mObj.interfaceId %>"><span
                                                    class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除</a>
                                    </li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                    <% }) %>
                    <% if(!list.length) { %>
                    <tr>
                        <td colspan="4">(无)</td>
                    </tr>
                    <% } %>
                    </tbody>
                </table>

            </div>


            <br/><br/><br/><br/><br/><br/>

            <div class="bs-docs-section">
                <div class="page-header">
                    <h1 id="ifManage">接口管理</h1>
                </div>
                <p class="lead">接口列表</p>

                <p>
                    <a class="btn btn-primary" href="#" role="button" id="newInterface">新增接口</a>
                    <a class="btn btn-info" href="#" role="button" id="newJspPage">新增JSP页面</a>
                </p>

                <table class="table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th scope="col" class="col-xs-1" nowrap>#</th>
                        <th scope="col" class="col-xs-2" nowrap>所属模块</th>
                        <th scope="col" class="col-xs-2" nowrap>接口名称</th>
                        <th scope="col" class="col-xs-1" nowrap>接口负责人</th>
                        <th scope="col" class="col-xs-5" nowrap>接口URL</th>
                        <th scope="col" class="col-xs-1" nowrap>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <%
                    var i = 0, j = 0;
                    list.forEach(function(mObj){
                        j++;
                        if(mObj.ifs){

                            i = 0;
                    %>
                    <tr>
                        <td colspan="6">
                            <h4 id="<%=mObj.interfaceId%>"><%= mObj.name %></h4>
                        </td>
                    </tr>
                    <%
                    mObj.ifs.forEach(function(ifObj){
                        i++;
                    %>
                    <tr>
                        <td valign="right"><%= j + '.' + i %></td>
                        <td valign="center"><%= mObj.name %></td>
                        <td valign="center"><%= ifObj.name %></td>
                        <td valign="center"><%= ifObj.detailInfo.author %></td>
                        <td valign="center" style="word-wrap:break-word;word-break:break-all;"><%= ifObj.detailInfo.url %></td>
                        <td valign="center">
                            <div class="btn-group">
                                <button type="button" class="btn btn-info dropdown-toggle btn-xs" data-toggle="dropdown"
                                        aria-haspopup="true" aria-expanded="false">
                                    接口操作 <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu">
                                    <li><a href="#" data-mid="<%= ifObj.interfaceId %>" class="if-btn-modify"><span
                                                    class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 修改</a>
                                    </li>
                                    <li role="separator" class="divider"></li>
                                    <li><a href="#" data-mid="<%= ifObj.interfaceId %>" class="if-btn-delete"><span
                                                    class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除</a>
                                    </li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                    <% })
                    } }) %>
                    <% if(!i) { %>
                    <tr>
                        <td colspan="5">(无)</td>
                    </tr>
                    <% } %>
                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>
<!-- Footer
================================================== -->
<footer class="bs-footer" role="contentinfo">
    <div class="container">

        <p>开发接口文档 &nbsp;&nbsp;&nbsp;&nbsp;<em>Author : xinxinran</em></p>

    </div>
</footer>

<!-- JS and analytics only. -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../dist/js/jquery.min.js"></script>


<script src="../dist/js/bootstrap.js"></script>

<script src="../dist/js/holder.min.js"></script>
<script src="../dist/js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

<script src="../dist/js/application.js"></script>
<script src="../lib/jquery.noty.packaged.min.js"></script>

<script type="text/javascript">
    window.fakeStorage = {
        _data: {},

        setItem: function (id, val) {
            return this._data[id] = String(val);
        },

        getItem: function (id) {
            return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
        },

        removeItem: function (id) {
            return delete this._data[id];
        },

        clear: function () {
            return this._data = {};
        }
    };

    function LocalStoreManager() {
        var localSupported = !!window.localStorage;
        this.storage = localSupported ? window.localStorage : window.fakeStorage;
    }

    LocalStoreManager.prototype.get = function (key) {
        var result = this.storage.getItem(key);
        if (result && result.charAt(0) === 's') {
            return result.substring(2);
        } else if (result && result.charAt(0) === 'o') {
            try {
                return JSON.parse(result.substring(2));
            } catch (ignore) {
            }
        }
        return null;
    };

    LocalStoreManager.prototype.set = function (key, content) {
        if (typeof content === 'string') {
            content = 's:' + content;
        } else if (typeof content === 'object' && content) {
            content = 'o:' + JSON.stringify(content);
        } else {
            content = null;
        }

        content && this.storage.setItem(key, content);
    };

    LocalStoreManager.prototype.remove = function (key) {

        this.storage.removeItem(key);
    };

</script>

<script type="text/javascript">
    $(function () {
        var $moduleWin = $('#moduleEditModal'), mForm = $('#moduleForm'),
            $ifWin = $('#ifEditModal'), $jspWin = $('#jspEditModal'),
            iForm = $('#ifForm'),jForm = $('#jspForm'),
            $ifParamTable = $('#iTableParam'), $iAttrTab = $('#iAttr'),
            $iResultDemo = $('#iResultDemo'), $jResultDemo = $('#jResultDemo'),
            $iTableProp = $('#iTableProp'),
            $jTableProp = $('#jTableProp'),
            ObjToString = Object.prototype.toString,
            ptRowTpl = '<tr class="pt-added">' +
                '<td><input class="form-control input-sm param-name" type="text" placeholder="参数名称" value="#{0}"></td>' +
                '<td><input class="form-control input-sm param-desc" type="text" placeholder="参数描述" value="#{1}"></td>' +
                '<td align="center">' +
                '<div class="btn-group" role="group" aria-label="...">' +
                '<button type="button" class="btn btn-success btn-sm param-btn-add">' +
                '<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>' +
                '</button>' +
                '<button type="button" class="btn btn-warning btn-sm param-btn-del">' +
                '<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>' +
                '</button>' +
                '</div>' +
                '</td>' +
                '</tr>',
            atRowTpl = '<tr class="attr-row-#{0}">' +
                '<td class="rs-attr-name">#{0}</td>' +
                '<td><input class="form-control input-sm param-desc json-attr-desc" type="text" placeholder="属性描述" data-attr-name="#{0}" value="#{1}"></td>' +
                '</tr>',
            pratRowTpl = '<tr class="_param-attr-row param-attr-row-#{0}">' +
                '<td class="rs-attr-name">#{0}</td>' +
                '<td><input class="form-control input-sm param-desc json-param-attr-desc" type="text" placeholder="属性描述" data-attr-name="#{0}" value="#{1}"></td>' +
                '</tr>',
            defaultDesc = {
                data: '返回的数据结果',
                query: '接口调用状态',
                code: '接口错误码，0:正常，1:错误',
                msg: 'code为1时的错误信息',
                state_code: '接口返回状态,1000为正确,其他值为异常',
                desc: '接口返回描述',
                time_stamp: '接口调用时间戳'
            }, pathVarRegx = /\/manage-([^/]+)\/?/,

            thisURL = window.location.pathname, pathInfo = pathVarRegx.exec(thisURL), appName = pathInfo[1],
            storeManager = new LocalStoreManager(), confirmWin = $('#confirmModal')
            , confirmCancelBtn = $('#confirmNeed'), btnParamFormType = $('#btnParamFormType'),
            btnParamJSONType = $('#btnParamJSONType'), formTypeTable = $('#formTypeTable'),
            jsonTypeTable = $('#jsonTypeTable'), paramAttrRow = $('#paramAttrRow'),
            nowIfParamType = 0, paramJSONDemo = $('#paramJSONDemo'),
            iAuthor = $('#iAuthor'), jAuthor = $('#jAuthor'), authorName;

        var initDeferred = new $.Deferred(), initPromise = initDeferred.promise();
        initDeferred.resolve();
        confirmWin.data('selfDeferred', initDeferred).data('selfPromise', initPromise);

        $('.pt-' + appName).addClass('active');

        $('body').on('change', '.json-attr-desc', function () {
            var keyId = 'if-temp-save-' + ($('#iId').val() || 'new'), storeObj = storeManager.get(keyId) || {};
            $('.json-attr-desc').each(function () {
                var $this = $(this), attrName = $this.data('attrName');
                storeObj[attrName] = $this.val();
            });

            storeManager.set(keyId, storeObj);
        }).on('click', '.if-btn-delete', function () {
            var iId = $(this).data('mid');
            showConfirm('确定要删除此接口么?').done(function (isConfirm) {
                isConfirm && $.post('/manage-' + appName + '/delIf/' + iId, {}, null, 'json').done(function (res) {
                    if (res.suc) {
                        window.location.reload();
                    }
                });
            });

        }).on('click', '.mana-module-delete', function () {
            var mId = $(this).data('mid');
            showConfirm('确定要删除此模块么?').done(function (isConfirm) {
                isConfirm && $.post('/manage-' + appName + '/delModule/' + mId, {}, null, 'json').done(function (res) {
                    if (res.suc) {
                        window.location.reload();
                    } else {
                        showAlert(res.err);
                    }
                });
            });
        }).on('click', '.alert-confirm-cancel', function () {
            var confirmPromise = confirmWin.data('confirmPromise');
            if (confirmPromise && confirmPromise.resolve) {
                confirmPromise.resolve(false);
            }
            confirmWin.modal('hide');
        }).on('click', '.alert-confirm-ok', function () {
            var confirmPromise = confirmWin.data('confirmPromise');
            if (confirmPromise && confirmPromise.resolve) {
                confirmPromise.resolve(true);
            }
            confirmWin.modal('hide');
        });

        function showConfirm(txt) {
            var deferred = new $.Deferred(), mainPromise = deferred.promise(),
                selfDeferred = new $.Deferred(), selfPromise = selfDeferred.promise(),
                nowSelfPromise = confirmWin.data('selfPromise');
            nowSelfPromise.done(function () {
                confirmCancelBtn.show();
                confirmWin.find('.alert-confirm-content').html(txt).end()
                    .data('confirmPromise', deferred).data('selfDeferred', selfDeferred).data('selfPromise', selfPromise).modal();
            });
            return mainPromise;
        }

        function showAlert(txt) {
            var deferred = new $.Deferred(), mainPromise = deferred.promise(),
                selfDeferred = new $.Deferred(), selfPromise = selfDeferred.promise(),
                nowSelfPromise = confirmWin.data('selfPromise');
            nowSelfPromise.done(function () {
                confirmCancelBtn.hide();
                confirmWin.find('.alert-confirm-content').html(txt).end()
                    .data('confirmPromise', deferred).data('selfDeferred', selfDeferred).data('selfPromise', selfPromise).modal();
            });
            return mainPromise;
        }

        confirmWin.on('hidden.bs.modal', function () {
            var nowSelfDeferred = confirmWin.data('selfDeferred');
            nowSelfDeferred.resolve(true);
        });

        $('#newModule').click(function () {
            mForm[0].reset();
            $moduleWin.modal();
        });

        $('#btnSaveModule').click(function () {
            var saveObj = {};
            mForm.find('input').each(function (_, inp) {
                inp = $(inp);
                saveObj[inp.attr('id')] = inp.val();
            });

            $.post('/manage-' + appName + '/saveModule', saveObj, null, 'json').done(function (res) {
                if (res.suc) {
                    window.location.reload();
                }
            });
            $moduleWin.modal('hide');
        });

        $('.mana-module-modify').click(function () {
            var $this = $(this), id = $this.data('mid');
            $('#mId').val(id);
            $this.parents('tr').find('td').each(function () {
                var $td = $(this), inpId = $td.data('objattr');
                if (inpId) {
                    $('#' + inpId).val($td.text());
                }
            });

            $moduleWin.modal();
        });

        btnParamFormType.click(function () {
            btnParamFormType.addClass('active');
            btnParamJSONType.removeClass('active');
            formTypeTable.removeClass('hide');
            jsonTypeTable.addClass('hide');

            nowIfParamType = 0;
        });

        btnParamJSONType.click(function () {
            btnParamFormType.removeClass('active');
            btnParamJSONType.addClass('active');
            formTypeTable.addClass('hide');
            jsonTypeTable.removeClass('hide');

            nowIfParamType =1;
        });

        $('#newInterface').click(function () {
            var an ;
            iForm[0].reset();
            $('.pt-added').remove();
            $iTableProp.empty();
            paramAttrRow.empty();
            $('#ifEditFirstTab').tab('show');
            btnParamFormType.addClass('active');
            btnParamJSONType.removeClass('active');
            formTypeTable.removeClass('hide');
            jsonTypeTable.addClass('hide');
            $('#paramJSONFault').hide();
            $ifWin.data('isOpen', true).modal();
            $('#iId').val('');

            nowIfParamType = 0;

            if(!authorName){
                an = storeManager.get('lastUsedAuthorName');
                if(!an){
                    $.getJSON('/helper/myName').done(function(info){iAuthor.val(authorName = info.userName)});
                }else{
                    iAuthor.val(an);
                }

            }else{
                iAuthor.val(authorName);
            }
        });


        $('#newJspPage').click(function () {
            var an ;
            jForm[0].reset();
            $('.pt-added').remove();
            $jTableProp.empty();
            //paramAttrRow.empty();
            $('#jspEditFirstTab').tab('show');

            $jspWin.data('isOpen', true).modal();
            $('#jId').val('');

            if(!authorName){
                an = storeManager.get('lastUsedAuthorName');
                if(!an){
                    $.getJSON('/helper/myName').done(function(info){jAuthor.val(authorName = info.userName)});
                }else{
                    jAuthor.val(an);
                }

            }else{
                jAuthor.val(authorName);
            }
        });

        $ifParamTable.delegate('.param-btn-add', 'click', function () {
            addParamRow();
        }).delegate('.param-btn-del', 'click', function () {
            $(this).parents('tr').remove();
        });

        function addParamRow(name, desc) {
            $ifParamTable.append(formatString(ptRowTpl, name || '', desc || ''));
        }

        paramJSONDemo.change(function () {
            var $this = $(this), demoContent = $this.val(), attrArray = $this.data('attrArray') || [],
                demoObj, demoAttrs, demoTrueAttrs, rowsOperation;
            var keyId = 'if-param-temp-save-' + ($('#iId').val() || 'new'), storeObj = storeManager.get(keyId);
            try {
                demoContent.replace(/[“”]/g, '"');
                demoObj = JSON.parse(demoContent);
            } catch (e) {
                try {
                    demoObj = (new Function('return ' + demoContent))();
                } catch (e) {
                    demoObj = null;
                }
            }

            if (!demoObj) {
                demoObj = {};
                $('#paramJSONFault').show();
            } else {
                $this.val(JSON.stringify(demoObj, null, 4));
                $('#paramJSONFault').hide();
            }

            demoAttrs = getAttrArray(demoObj);
            demoTrueAttrs = demoAttrs[1];
            demoAttrs = demoAttrs[0];

            if (!demoAttrs.length) {
                $this.data('attrArray', []);
                paramAttrRow.empty();
            } else {
                $this.data('attrArray', demoAttrs);
                rowsOperation = compareArrays(attrArray, demoAttrs, demoTrueAttrs);
                rowsOperation.add.forEach(function (n, i) {
                    addParamAttrRow(n, null, storeObj);
                });
                rowsOperation.del.forEach(function (n) {
                    delParamAttrRow(n)
                });
            }
        });

        $iResultDemo.change(function () {
            var $this = $(this), attrArray = $this.data('attrArray') || [], demoContent = $iResultDemo.val(),
                demoObj, demoAttrs, demoTrueAttrs, rowsOperation, isValidJson;
            var keyId = 'if-temp-save-' + ($('#iId').val() || 'new'), storeObj = storeManager.get(keyId);
            try {
                demoContent.replace(/[“”]/g, '"');
                demoObj = JSON.parse(demoContent);
            } catch (e) {
                try {
                    demoObj = (new Function('return ' + demoContent))();
                } catch (e) {
                    demoObj = null;
                }

            }

            if (!demoObj) {
                demoObj = {};
                $('.json-check-alert').show();
            } else {
                $iResultDemo.val(JSON.stringify(demoObj, null, 4));
                $('.json-check-alert').hide();
            }

            demoAttrs = getAttrArray(demoObj);
            demoTrueAttrs = demoAttrs[1];
            demoAttrs = demoAttrs[0];

            if (!demoAttrs.length) {
                $this.data('attrArray', []);
                $iTableProp.empty();
            } else {
                $this.data('attrArray', demoAttrs);
                rowsOperation = compareArrays(attrArray, demoAttrs, demoTrueAttrs);
                rowsOperation.add.forEach(function (n, i) {
                    addAttrRow(n, null, storeObj);
                });
                rowsOperation.del.forEach(function (n) {
                    delAttrRow(n)
                });
            }
        });

        $jResultDemo.change(function () {
            var $this = $(this), attrArray = $this.data('attrArray') || [], demoContent = $jResultDemo.val(),
                demoObj, demoAttrs, demoTrueAttrs, rowsOperation, isValidJson;
            var keyId = 'if-temp-save-' + ($('#jId').val() || 'new'), storeObj = storeManager.get(keyId);
            try {
                demoContent.replace(/[“”]/g, '"');
                demoObj = JSON.parse(demoContent);
            } catch (e) {
                try {
                    demoObj = (new Function('return ' + demoContent))();
                } catch (e) {
                    demoObj = null;
                }

            }

            if (!demoObj) {
                demoObj = {};
                $('.json-check-alert').show();
            } else {
                $jResultDemo.val(JSON.stringify(demoObj, null, 4));
                $('.json-check-alert').hide();
            }

            demoAttrs = getAttrArray(demoObj);
            demoTrueAttrs = demoAttrs[1];
            demoAttrs = demoAttrs[0];

            if (!demoAttrs.length) {
                $this.data('attrArray', []);
                $jTableProp.empty();
            } else {
                $this.data('attrArray', demoAttrs);
                rowsOperation = compareArrays(attrArray, demoAttrs, demoTrueAttrs);
                rowsOperation.add.forEach(function (n, i) {
                    addAttrRow(n, null, storeObj, true);
                });
                rowsOperation.del.forEach(function (n) {
                    delAttrRow(n)
                });
            }
        });

        function addAttrRow(name, desc, descStoreObj, isJSP) {
            descStoreObj = descStoreObj || defaultDesc;
            (isJSP ? $jTableProp : $iTableProp).append(formatString(atRowTpl, name, desc || descStoreObj[name] || ''));
        }

        function addParamAttrRow(name, desc, descStoreObj) {
            descStoreObj = descStoreObj || defaultDesc;
            paramAttrRow.append(formatString(pratRowTpl, name, desc || descStoreObj[name] || ''));
        }

        function delAttrRow(name) {
            $('.attr-row-' + name).remove();
        }

        function delParamAttrRow(name) {
            $('.param-attr-row-' + name).remove();
        }

        function getAttrArray(obj) {
            var res = [], resTrue = [];
            processAttrArray(obj, res, '', resTrue);
            return [res, resTrue];
        }

        function processAttrArray(obj, attrArray, prefix, attrTrueArray) {
            var attr;
            if (!obj || typeof obj !== 'object') {
                return;
            }

            if (ObjToString.call(obj) === '[object Array]') {
                processAttrArray(obj[0], attrArray, prefix, attrTrueArray);
                return;
            }

            for (attr in obj) {
                if (obj.hasOwnProperty(attr) && attr.charAt(0) !== '_') {
                    attrArray && attrArray.push(attr);
                    attrTrueArray && attrTrueArray.push(prefix + attr);
                    processAttrArray(obj[attr], attrArray, prefix + attr + '.', attrTrueArray);
                }
            }
        }

        function compareArrays(oriArray, newArray) {
            var sameItems = [], delItems = [], newItems = [];
            newArray.forEach(function (item) {
                if (~oriArray.indexOf(item)) {
                    sameItems.push(item);
                } else {
                    newItems.push(item);
                }
            });

            oriArray.forEach(function (item) {
                if (!~sameItems.indexOf(item)) {
                    delItems.push(item);
                }
            });

            return {
                same: sameItems,
                del: delItems,
                add: newItems
            };
        }

        function formatString(txt, obj) {
            var arr = Array.prototype.slice.call(arguments, 1);
            return txt.replace(/\\?#\{([^{}]+)}/gm, function (match, name) {
                if (match.charAt(0) === '\\') {
                    return match.slice(1);
                }
                var index = Number(name);
                if (index >= 0) {
                    return arr[index];
                }
                if (obj && obj[name] !== void 0) {
                    return obj[name];
                }
                return '';
            });
        }

        $('#btnSaveIf').click(function () {
            var saveObj = {}, params = [], attrs = [], ans = $iResultDemo.data('attrArray') || [], i = 0;
            saveObj.mId = $('#iId').val();
            saveObj.parentId = $('#iModule').val();
            saveObj.name = $('#iName').val();
            saveObj.ifType = 'if';
            saveObj.url = $('#iUrl').val();
            saveObj.order = $('#iOrder').val();
            saveObj.desc = $('#iDesc').val();
            saveObj.code = '';
            saveObj.resultDemo = $iResultDemo.val();
            saveObj.interfaceId = $('iId').val();
            saveObj.paramType = nowIfParamType;
            saveObj.author = iAuthor.val();

            saveObj.author && storeManager.set('lastUsedAuthorName', saveObj.author);

            if(nowIfParamType){
                params.push(paramJSONDemo.val());
                paramAttrRow.find('tr').each(function(){
                    var $tr = $(this), n = $tr.find('.rs-attr-name').text().replace(/\|/g, ''),
                        d = $tr.find('input').val().replace(/\|/g, '');
                    if (n) {
                        params.push(n + '|' + d);
                    }
                });
            }else{
                $ifParamTable.find('tr').each(function () {
                    var $tr = $(this), n = $tr.find('.param-name').val().replace(/\s/g, '').replace(/\|/g, ''),
                        d = $tr.find('.param-desc').val().replace(/\|/g, '');
                    if (n) {
                        params.push(n + '|' + d);
                    }
                });
            }


            saveObj.params = params;

            $iTableProp.find('tr').each(function () {
                var $tr = $(this), n = $tr.find('.rs-attr-name').text().replace(/\|/g, ''),
                    d = $tr.find('input').val().replace(/\|/g, '');

                if (n) {
                    attrs.push(n + '|' + d);
                }
            });

            saveObj.attrInfos = attrs;

            $.post('/manage-' + appName + '/saveInterface', saveObj, null, 'json').done(function (res) {
                if (res.suc) {
                    storeManager.remove('if-temp-save-' + ($('#iId').val() || 'new'));
                    storeManager.remove('if-param-temp-save-' + ($('#iId').val() || 'new'));
                    window.location.reload();
                    $ifWin.data('isOpen', false).modal('hide');
                }else{
                    notyAlert('保存异常：' + res.err);
                }
            }).fail(function(err){
                notyAlert('保存异常：' + err);
            });

        });

        $('#btnSaveJspPage').click(function () {
            var saveObj = {}, attrs = [], ans = $jResultDemo.data('attrArray') || [], i = 0;
            saveObj.mId = $('#jId').val();
            saveObj.parentId = $('#jModule').val();
            saveObj.ifType = 'jsp';
            saveObj.name = $('#jName').val();
            saveObj.url = $('#jUrl').val();
            saveObj.order = $('#jOrder').val();
            saveObj.desc = '';
            saveObj.code = '';
            saveObj.resultDemo = $jResultDemo.val();
            saveObj.resultPage = $('#jPage').val();
            saveObj.interfaceId = $('jId').val();
            saveObj.author = jAuthor.val();

            saveObj.author && storeManager.set('lastUsedAuthorName', saveObj.author);

            if(!saveObj.url || !saveObj.resultPage){
                notyAlert('页面访问URL以及资源路径是必填项');
                return;
            }

            $jTableProp.find('tr').each(function () {
                var $tr = $(this), n = $tr.find('.rs-attr-name').text().replace(/\|/g, ''),
                    d = $tr.find('input').val().replace(/\|/g, '');

                if (n) {
                    attrs.push(n + '|' + d);
                }
            });

            saveObj.attrInfos = attrs;

            $.post('/manage-' + appName + '/saveInterface', saveObj, null, 'json').done(function (res) {
                if (res.suc) {
                    storeManager.remove('if-temp-save-' + ($('#iId').val() || 'new'));
                    storeManager.remove('if-param-temp-save-' + ($('#iId').val() || 'new'));
                    window.location.reload();
                    $ifWin.data('isOpen', false).modal('hide');
                }else{
                    notyAlert('保存异常：' + res.err);
                }
            }).fail(function(err){
                notyAlert('保存异常：' + err);
            });

        });

        $('.if-btn-modify').click(function () {
            var iId = $(this).data('mid');
            $.get('/manage-' + appName + '/getIf/' + iId, null, null, 'json').done(function (res) {
                var ifObj = res.result, pArray = ifObj.detailInfo.params, aArray = ifObj.detailInfo.attrInfos, firstP,
                    ans = [], pns = [], attrStorage = {}, paramAttrStorage = {}, paramDemo, ifType = ifObj.detailInfo.ifType;
                if(ifType === 'jsp'){
                    $('#jModule').val(ifObj.parentId);
                    $('#jName').val(ifObj.name);
                    $('#jUrl').val(ifObj.detailInfo.url);
                    $('#jOrder').val(ifObj.order);
                    $('#jPage').val(ifObj.detailInfo.resultPage);

                    $jResultDemo.val(ifObj.detailInfo.resultDemo);
                    $('#jId').val(ifObj.interfaceId);
                    jAuthor.val(ifObj.detailInfo.author);

                    try {
                        JSON.parse(ifObj.detailInfo.resultDemo);
                        $('.json-check-alert').hide();
                    } catch (e) {
                        $('.json-check-alert').show();
                    }

                    $jTableProp.empty();
                    aArray && aArray.forEach(function (aInfo) {
                        aInfo = aInfo.split('|');
                        attrStorage[aInfo[0]] = aInfo[1];
                        addAttrRow(aInfo[0], aInfo[1], null, true);
                        ans.push(aInfo[0])
                    });

                    storeManager.set('if-temp-save-' + ifObj.interfaceId, attrStorage);

                    $jResultDemo.data('attrArray', ans);
                    $('#jspEditFirstTab').tab('show');
                    $jspWin.data('isOpen', true).modal();

                }else{
                    $('#iModule').val(ifObj.parentId);
                    $('#iName').val(ifObj.name);
                    $('#iUrl').val(ifObj.detailInfo.url);
                    $('#iOrder').val(ifObj.order);
                    $('#iDesc').val(ifObj.detailInfo.desc);
                    $iResultDemo.val(ifObj.detailInfo.resultDemo);
                    $('#iId').val(ifObj.interfaceId);
                    iAuthor.val(ifObj.detailInfo.author);

                    try {
                        JSON.parse(ifObj.detailInfo.resultDemo);
                        $('.json-check-alert').hide();
                    } catch (e) {
                        $('.json-check-alert').show();
                    }

                    nowIfParamType = ifObj.detailInfo.paramType || 0;

                    if(nowIfParamType){
                        btnParamFormType.removeClass('active');
                        btnParamJSONType.addClass('active');
                        formTypeTable.addClass('hide');
                        jsonTypeTable.removeClass('hide');

                        paramAttrRow.empty();

                        paramDemo = pArray.shift();
                        paramJSONDemo.val(paramDemo);
                        pArray && pArray.forEach(function (aInfo) {
                            aInfo = aInfo.split('|');
                            paramAttrStorage[aInfo[0]] = aInfo[1];
                            addParamAttrRow(aInfo[0], aInfo[1]);
                            pns.push(aInfo[0])
                        });

                        paramJSONDemo.data('attrArray', pns);
                    }else{
                        btnParamFormType.addClass('active');
                        btnParamJSONType.removeClass('active');
                        formTypeTable.removeClass('hide');
                        jsonTypeTable.addClass('hide');

                        $('.pt-added').remove();
                        firstP = pArray && pArray.shift();
                        if (firstP) {
                            firstP = firstP.split('|');
                            $('.param-first-row').find('.param-name').val(firstP[0]).end().find('.param-desc').val(firstP[1]);
                        }
                        pArray && pArray.forEach(function (pInfo) {
                            pInfo = pInfo.split('|');
                            addParamRow(pInfo[0], pInfo[1]);
                        });
                    }

                    $iTableProp.empty();
                    aArray && aArray.forEach(function (aInfo) {
                        aInfo = aInfo.split('|');
                        attrStorage[aInfo[0]] = aInfo[1];
                        addAttrRow(aInfo[0], aInfo[1]);
                        ans.push(aInfo[0])
                    });

                    storeManager.set('if-temp-save-' + ifObj.interfaceId, attrStorage);

                    $iResultDemo.data('attrArray', ans);
                    $('#ifEditFirstTab').tab('show');
                    $ifWin.data('isOpen', true).modal();

                }
            });
        });


        $('#toView').click(function () {
            window.location.href = '/view-' + appName;
        });

        function notyAlert(text, level){
            noty({
                layout : 'topCenter',
                type : level || 'error',
                text : text
            });
        }
    });
</script>
</body>
</html>
